package com.study.consumer;


import com.study.api.DemoService;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;

/**
 <dubbo:application name="demo-consumer"/>
 <dubbo:registry address="multicast://224.5.6.7:1234"/>
 <dubbo:reference id="demoService" check="false" interface="com.alibaba.dubbo.demo.DemoService"/>
 */
public class Consumer {

    public static void main(String[] args) {
        //应用配置
        ApplicationConfig application = new ApplicationConfig("demo");
        //注册中心配置
        //RegistryConfig registry = new RegistryConfig("multicast://224.5.6.7:1234");
        //引用配置
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setApplication(application);
        //reference.setRegistry(registry);
        reference.setUrl("dubbo://localhost:20880/?com.alibaba.dubbo.demo.DemoService?version=1.0.0");
        reference.setInterface(DemoService.class);
        reference.setVersion("1.0.0");

        // 和本地bean一样使用xxxService
        DemoService demoService = reference.get(); // 注意：此代理对象内部封装了所有通讯细节，对象较重，请缓存复用
        System.out.println(demoService.sayHello("hello"));
    }
}
